package com.xmg.mgrsite.base;

import com.xmg.p2p.base.domain.Userinfo;
import com.xmg.p2p.base.service.IRealAuthService;
import com.xmg.p2p.base.service.IUserFileService;
import com.xmg.p2p.base.service.IUserinfoService;
import com.xmg.p2p.base.util.BidConst;
import com.xmg.p2p.base.util.JSONResult;
import com.xmg.p2p.business.domain.BidRequest;
import com.xmg.p2p.business.query.BidRequestQueryObject;
import com.xmg.p2p.business.service.IBidRequestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * lcd  2020/5/25
 * Description:后台
 */
@Controller
public class BidRequestController {
    @Autowired
    private IBidRequestService bidRequestService;
    @Autowired
    private IRealAuthService realAuthService;
    @Autowired
    private IUserFileService userFileService;
    @Autowired
    private IUserinfoService userinfoService;

    //列表展示
    @RequestMapping("bidrequest_publishaudit_list")
    public String bidrequest_publishaudit_list(Model model, @ModelAttribute("qo") BidRequestQueryObject qo) {
        qo.setBidRequestState(BidConst.BIDREQUEST_STATE_PUBLISH_PENDING);
        model.addAttribute("pageResult", bidRequestService.queryPage(qo));
        return "bidrequest/publish_audit";
    }
    //发标前审核
    @RequestMapping("bidrequest_publishaudit")
    @ResponseBody
    public JSONResult bidRequestPublishAudit(long id,int state,String remark){
        bidRequestService.audit(id,state,remark);
        return new JSONResult();
    }

    @RequestMapping("borrow_info")
    public String borrowInfo(long id,Model model){
        BidRequest bidRequest = bidRequestService.findById(id);
        model.addAttribute("bidRequest", bidRequest);
        Userinfo userinfo = userinfoService.findById(bidRequest.getCreateUser().getId());
        model.addAttribute("userInfo", userinfo);
        model.addAttribute("audits",bidRequestService.listByBidRequestId(bidRequest.getId()));
        model.addAttribute("realAuth",realAuthService.findById(userinfo.getRealAuthId()));
        model.addAttribute("userFiles",userFileService.query(bidRequest.getCreateUser().getId(),true));
        return "bidrequest/borrow_info";
    }
    //满标一审列表展示
    @RequestMapping("bidrequest_audit1_list")
    public String bidRequestAudit1List(Model model, @ModelAttribute("qo") BidRequestQueryObject qo) {
        qo.setBidRequestState(BidConst.BIDREQUEST_STATE_APPROVE_PENDING_1);
        model.addAttribute("pageResult", bidRequestService.queryPage(qo));
        return "bidrequest/audit1";
    }

    @RequestMapping("bidrequest_audit1")
    @ResponseBody
    public JSONResult fullAudit1(Long id,int state,String remark){
        bidRequestService.fullAudit1(id, state, remark);
        return new JSONResult();
    }
    //满标二审
    @RequestMapping("bidrequest_audit2_list")
    public String bidRequestAudit2List(Model model, @ModelAttribute("qo") BidRequestQueryObject qo) {
        qo.setBidRequestState(BidConst.BIDREQUEST_STATE_APPROVE_PENDING_2);
        model.addAttribute("pageResult", bidRequestService.queryPage(qo));
        return "bidrequest/audit2";
    }

    @RequestMapping("bidrequest_audit2")
    @ResponseBody
    public JSONResult fullAudit2(Long id,int state,String remark){
        bidRequestService.fullAudit2(id, state, remark);
        return new JSONResult();
    }
}
